'''
@author: Kevin Zhao
@date: Jan 7,2013
'''


'''
Static Circular Queue implemented with a normal array
'''
from linked_list import SinglyLinkedList
class ArrayQueue:
    head = 0
    tail = 0
    current_size=0
    array = []
    def __init__(self, values=None):
        self.array = [0] * values #create a array of initial capacity
        
    def enqueue(self, x):

        if self.current_size == len(self.array):
            print 'queue overflows'
            return None

        self.array[self.tail] = x
        self.current_size +=1
        self.tail+=1
        if self.tail > len(self.array) - 1:
            self.tail = 0
        
            
        
    
    def dequeue(self):
        if self.current_size ==0:
            print 'queue underflows'
            return None
        result = self.array[self.head]
        self.head += 1
        self.current_size -=1
        return result 
    def clear(self):
        self.head = 0
        self.tail = 0
        self.array=[]
        self.current_size = 0
        
'''
Dynamic Circular Queue implemented with a singly linked list
Exercise 10.2-3
'''
class SinglyLinkedQueue:
    count = 0
    linked_list = SinglyLinkedList()
    def enqueue(self, x):
        self.linked_list.insert(x)
        self.count +=1
        
    def dequeue(self):
        if self.count == 0:
            print 'empty queue'
            return None
        self.count -=1
        result_value = self.linked_list.deleteByIndex(0)
        return result_value
    def clear(self):
        self.count = 0
        self.linked_list = SinglyLinkedList()
'''
Static Circular Queue implemented with a doubly linked list
'''
class DoublyLinkedQueue:
    head = None
    tail = None
    def enqueue(self, x):
        return
    def dequeue(self):
        return
